﻿
// MFCApplication1View.cpp: CMFCApplication1View 类的实现
//

#include "pch.h"
#include "framework.h"
// SHARED_HANDLERS 可以在实现预览、缩略图和搜索筛选器句柄的
// ATL 项目中进行定义，并允许与该项目共享文档代码。
#ifndef SHARED_HANDLERS
#include "MFCApplication1.h"
#endif

#include "MFCApplication1Doc.h"
#include "MFCApplication1View.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CMFCApplication1View

IMPLEMENT_DYNCREATE(CMFCApplication1View, CView)

BEGIN_MESSAGE_MAP(CMFCApplication1View, CView)
	ON_WM_LBUTTONDOWN()
END_MESSAGE_MAP()

// CMFCApplication1View 构造/析构

CMFCApplication1View::CMFCApplication1View() noexcept
{
	// TODO: 在此处添加构造代码

}

CMFCApplication1View::~CMFCApplication1View()
{
}

BOOL CMFCApplication1View::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: 在此处通过修改
	//  CREATESTRUCT cs 来修改窗口类或样式

	return CView::PreCreateWindow(cs);
}

// CMFCApplication1View 绘图

void CMFCApplication1View::OnDraw(CDC* pDC)
{
	CMFCApplication1Doc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;
	//绘制每一个格子
	for (int i = 0; i < 4; i++)
		for (int j = 0; j < 4; j++)
		{
			CRect rect(50 + j * 100, 50 + i * 100, 50 + (j + 1) * 100, 50 + (i + 1) * 100);
			pDC->FillSolidRect(rect, pDoc->GetBoxColor(i, j));
		}

	//绘制网格线条
	for (int i = 0; i < 5; i++)
	{
		//绘制水平线
		pDC->MoveTo(50, 50 + i * 100);
		pDC->LineTo(50 + 4 * 100, 50 + i * 100);
		//绘制垂直线
		pDC->MoveTo(50 + i * 100, 50);
		pDC->LineTo(50 + i * 100, 50 + 4 * 100);
	}
}


// CMFCApplication1View 诊断

#ifdef _DEBUG
void CMFCApplication1View::AssertValid() const
{
	CView::AssertValid();
}

void CMFCApplication1View::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CMFCApplication1Doc* CMFCApplication1View::GetDocument() const // 非调试版本是内联的
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMFCApplication1Doc)));
	return (CMFCApplication1Doc*)m_pDocument;
}
#endif //_DEBUG


// CMFCApplication1View 消息处理程序

void CMFCApplication1View::OnLButtonDown(UINT nFlags, CPoint point)
{
	int x = (point.x - 50) / 100;
	int y = (point.y - 50) / 100;
	if (x >= 0 && x < 4 && y >= 0 && y < 4)
	{
		GetDocument()->SetBoxColor(y, x);
	}

	CView::OnLButtonDown(nFlags, point);
}
